package com.ute.chinesechess;

public class QuanCo {

	int Hang;
	int Cot;
	int Phe;
	int ThuTu;
	String Ten;
	boolean Song;
	boolean TrangThai; // Cho biet co the di chuyen hay khong

	public QuanCo() {
		Hang = Cot = -1;
		Phe = ThuTu = -1;
		Song = TrangThai = true;
		Ten = "";
	}

	public void KhoiTao(int x, int y, String Ten, int Phe, int ThuTu,
			boolean TrangThai, boolean Song) {
		this.Ten = Ten;
		this.Hang = x;
		this.Cot = y;
		this.Phe = Phe;
		this.ThuTu = ThuTu;
		this.TrangThai = TrangThai;
		this.Song = Song;
	}

	public boolean setViTri(int i, int j) {
		this.Hang = i;
		this.Cot = j;
		return true;
	}

	public boolean KiemTra(int i, int j) {
		return false;
	}

	public boolean Move(int iSau, int jSau) {
		// Lay vi tri o co
		int iTruoc = Hang;
		int jTruoc = Cot;
		QuanCo qc = new QuanCo();
		OCo sau = new OCo();
		OCo truoc = new OCo();
		
		sau.Phe = BanCo.board[iSau][jSau].Phe;
		sau.Trong = BanCo.board[iSau][jSau].Trong;
		sau.ThuTu = BanCo.board[iSau][jSau].ThuTu;
		sau.Ten = BanCo.board[iSau][jSau].Ten;
		
		truoc.Phe = BanCo.board[iTruoc][jTruoc].Phe;
		truoc.Trong = BanCo.board[iTruoc][jTruoc].Trong;
		truoc.ThuTu = BanCo.board[iTruoc][jTruoc].ThuTu;
		truoc.Ten = BanCo.board[iTruoc][jTruoc].Ten;
		//Kiem tra xem quan co co the di den vi tri Sau?
		if (KiemTra(iSau, jSau) == true) {
			setViTri(iSau, jSau);
			if (BanCo.board[iSau][jSau].Trong == false) {
				qc = BanCo.timQuanCo(iSau, jSau);
				qc.Song = false;
			}
			//GIA SU DI TOI VI TRI SAU
			BanCo.board[iSau][jSau].Phe = BanCo.board[iTruoc][jTruoc].Phe;
			BanCo.board[iSau][jSau].Trong = false;
			BanCo.board[iSau][jSau].ThuTu = BanCo.board[iTruoc][jTruoc].ThuTu;
			BanCo.board[iSau][jSau].Ten = BanCo.board[iTruoc][jTruoc].Ten;
			
			BanCo.board[iTruoc][jTruoc].reset();	//Xoa thang truoc
			//Sau khi di chuyen den vi tri sau
			if (VanCo.TuongAnToan(this.Phe) == true) {
				
				setViTri(iTruoc, jTruoc);
				
				BanCo.board[iTruoc][jTruoc].Phe = truoc.Phe;
				BanCo.board[iTruoc][jTruoc].Trong = truoc.Trong;
				BanCo.board[iTruoc][jTruoc].ThuTu = truoc.ThuTu;
				BanCo.board[iTruoc][jTruoc].Ten = truoc.Ten;
				
				qc.Song = true;
				
				BanCo.board[iSau][jSau].Phe = sau.Phe;
				BanCo.board[iSau][jSau].Trong = sau.Trong;
				BanCo.board[iSau][jSau].ThuTu = sau.ThuTu;
				BanCo.board[iSau][jSau].Ten = sau.Ten;
				
				return true;
			}
			setViTri(iTruoc, jTruoc);
			
			qc.Song = true;
			
			BanCo.board[iTruoc][jTruoc].Phe = truoc.Phe;
			BanCo.board[iTruoc][jTruoc].Trong = truoc.Trong;
			BanCo.board[iTruoc][jTruoc].ThuTu = truoc.ThuTu;
			BanCo.board[iTruoc][jTruoc].Ten = truoc.Ten;
			
			BanCo.board[iSau][jSau].Phe = sau.Phe;
			BanCo.board[iSau][jSau].Trong = sau.Trong;
			BanCo.board[iSau][jSau].ThuTu = sau.ThuTu;
			BanCo.board[iSau][jSau].Ten = sau.Ten;
		}
		return false;
	}

}
